#include "stdafx.h"
#include "get_ip_city.h"
#include <utility/xml_http.h>
#include <stdio.h>
#include <utility/api_tools.h>
#include <utility/ini_op.h>
#include "dll_manager.h"

get_ip_city::get_ip_city()
{
	this->is_exit_ = FALSE;
}

void get_ip_city::ActualWorkerThreadProc(PWORKER_PARAMETER work_para)
{
	aot::tt::utility::ini_op ini;
	std::string id = dll_manager::instance()->get_main_obj()->glb_data_->user_mgr_.id();
	std::string path = dll_manager::instance()->get_main_obj()->get_config_path();
	path += "\\web_srv.ini";

	int isexist = ::GetFileAttributes(path.c_str());
	if( isexist == INVALID_FILE_ATTRIBUTES )
	{
		return;
	}
	ini.file_name(path.c_str());
	std::string url;
	url = ini.read("URL", "ipaddress", "");

	CXml_Http http_ctrl;
	http_ctrl.open(url.c_str(), "GET");
	http_ctrl.send_str();
	std::string cityinfo;
	http_ctrl.recv(cityinfo, "GBK");
	::SendMessage(this->notify_hwnd_, WM_RECV_IP_CITY, (WPARAM)cityinfo.c_str(), 0);
}

void get_ip_city::OnBeforeExiting()
{
	this->is_exit_ = TRUE;
}